<?php

namespace App\Http\Controllers;

use App\Models\ClassModel;
use App\Models\CollegeaModel;
use App\Models\ManageModel;
use App\Models\StudentModel;
use App\Models\TeacherModel;
use App\Toor\Tranks;
use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Redis;

class LoginController extends Tranks
{

    public function index(Request $request)
    {
        switch ($request['key']){
            case 1:
                $student = StudentModel::where('studentid',$request['user'])->get();
                if ($student[0]['password']==$request['password']){
                    return rsps('200',['token'=>$this->getToken($student)],'成功响应');
                }else{
                    return rsps('400','验证错误','验证错误');
                }
                break;
            case 2:
                $student = TeacherModel::where('studentid',$request['user'])->get();
                if ($student[0]['password']==$request['password']){
                    return rsps('200',['token'=>$this->getToken($student)],'成功响应');
                }else{
                    return rsps('400','验证错误','验证错误');
                }
                break;
            case 3:
                $student = ManageModel::where('teacher',$request['user'])->get();
                if ($student[0]['teacher']==$request['password']){
                    return rsps('200',['token'=>$this->getToken($student)],'成功响应');
                }else{
                    return rsps('400','验证错误','验证错误');
                }
                break;
        }
    }

    public function chateToken(Request $request)
    {
//        return $this->deToken($request->header('token'));
        $input_params =  $request->header('token');//获取参数
//        $mid_params = $request->get($input_params);//中间件产生的参数
        $redisDate = json_decode(Redis::get($input_params));
        return rsps("200",$redisDate,'成功响应');

    }

}
